package in.blogspot.khurram2java;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.AutoCompleteTextView;
import android.widget.SimpleAdapter;

public class SearchEntries extends Activity{
	AutoCompleteTextView searchQueryTextView;
	List<Info> info;
	DbAdapter dbAdapter = new DbAdapter(this);
	static final String KEY_ISBN = "isbn";
	static final String KEY_NAME = "name"; 
	static final String KEY_EMAIl = "email";
	static final String KEY_AUTHOR = "author";
	static final String KEY_STYLE = "style";
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        
     // Each row in the list stores username and email
        List<HashMap<String,String>> entryList = new ArrayList<HashMap<String,String>>();
        String[] ISBN = dbAdapter.getItems(KEY_ISBN);
        String[] ENTRIES = dbAdapter.getItems(KEY_NAME);
        String[] EMAIL = dbAdapter.getItems(KEY_EMAIl);
        String[] AUTHOR = dbAdapter.getItems(KEY_AUTHOR);
        String[] STYLE = dbAdapter.getItems(KEY_STYLE);
        
        for(int i=0;i<ENTRIES.length;i++){
            HashMap<String, String > hm = new HashMap<String,String>();
            hm.put("isbn", ISBN[i]);
            hm.put("username", ENTRIES[i]);
            hm.put("email", EMAIL[i]);
            hm.put("author", AUTHOR[i]);
            hm.put("style", STYLE[i]);
            entryList.add(hm);
        }
 
        // Keys used in Hashmap
        String[] from = { "isbn","username","email","author","style"};
 
        // Ids of views in listview_layout
        int[] to = { R.id.Isbn,R.id.userNameText,R.id.emailText,R.id.Author,R.id.Style};
 
        // Instantiating an adapter to store each items
        SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), entryList, R.layout.list_view, from, to);
 
        CustomAutoCompleteTextView autoComplete = ( CustomAutoCompleteTextView) findViewById(R.id.autocomplete);
 
        /** Setting the adapter to the listView */
        autoComplete.setAdapter(adapter);
        autoComplete.setThreshold(1);
 
    }
	
}
